package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbItemCatMapper;
import com.bw1806.pojo.TbItemCat;
import com.bw1806.pojo.TbItemCatExample;
import com.bw1806.sellergoods.service.TbItemCatService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbItemCatServiceImpl implements TbItemCatService {

    @Autowired
    private TbItemCatMapper tbItemCatMapper;

    @Override
    public List<TbItemCat> findAll() {
        return tbItemCatMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbItemCat> pagelist(TbItemCat tbItemCat,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbItemCatExample example=new TbItemCatExample();

        TbItemCatExample.Criteria criteria = example.createCriteria();

        if(tbItemCat!=null){
            //if(tbItemCat.getName()!=null && tbItemCat.getName().length()>0){
            //    criteria.andNameLike("%"+tbItemCat.getName()+"%");
           // }
        }

        Page<TbItemCat> page= (Page<TbItemCat>) tbItemCatMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbItemCat tbItemCat) {
        Long id = tbItemCat.getId();
        if(id != null && id !=0){
            tbItemCatMapper.updateByPrimaryKey(tbItemCat);
        } else{
            tbItemCatMapper.insert(tbItemCat);
        }
    }

    @Override
    public TbItemCat getById(Long id) {
        return tbItemCatMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbItemCatMapper.deleteByPrimaryKey(id);
        }
        //tbItemCatMapper.deletebth(ids);
    }
}
